package com.ejuornal.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ejuornal.bean.Artical;
import com.ejuornal.service.ArticalService;
import com.ejuornal.springutil.SpringUtil;

@Component("articalAction")
@Scope("prototype")
public class ArticalListAction extends BaseAction<Artical> {
	private static final long serialVersionUID = 1L;
	private ArticalService articalService;
	private Artical artical;
	private String articalString;
	private int value;
	
	
	
	//根据期刊状态查询
	public String findByStatus() {
		String url= "user/findByStatus?value=" + value+"&";
		articalService = (ArticalService)SpringUtil.getBean("articalService");
		if(value == 0) {	//查询未审核的期刊
			pages = articalService.findByStatus((page-1)*10, url, "未审核");
			return "uncheck";
		} else if(value == 1) {	//查询已审核的期刊
			pages = articalService.findByStatus((page-1)*10, url, "一审已通过");
			return "success";
		} else if(value == 2){	//查询停刊期刊
			pages = articalService.findByStatus((page-1)*10, url, "二审已通过");
			return "success";
		} else if(value == 3){	//查询停刊期刊
			pages = articalService.findByStatus((page-1)*10, url, "三审已通过");
			return "success";
		} else{
			return "error";	//异常处理
		}
	}
	//	显示所有文章列表
	public  String listArtical()
	{
		String urlString="user/listArtical?";
		articalService=(ArticalService) SpringUtil.getBean("articalService");
		if(artical.getStatus().equals("三审已通过"))
		{
			pages=articalService.findAll((page - 1) * 10, urlString);
			return SUCCESS;
		}
		return "error";
	}
	//显示文章详情
	public String detailString(){
		articalService=(ArticalService) SpringUtil.getBean("articalService");
		artical=articalService.findById(Integer.parseInt(articalString));
		return SUCCESS;
	}
	
	//	显示文章列表前多少条
	public  String listTopArtical()
	{
		List<Artical> list=articalService.findTop(10);
		super.setRequestAttribute("artical", list);
		return SUCCESS;
	}
	
	/*--------不知道这下面方法用到没--------*/
	/**
	 * 查询一篇文章的详情
	 * @return
	 */
	/*public  String getDetailByArticalId(){
		artical=articalService.findById(artical.getArticalId());

		return SUCCESS;
	}*/
	
	/**
	 * 查找所有的列表
	 * @return
	 *//*
	public String getArticalTitlesByStatus(){
		articalService=(ArticalService) SpringUtil.getBean("articalService");
		String url = "artical/getArticalTitlesByStatus";
		pages = articalService.findByStatus((page - 1)*10, url, "三审已通过");
		return SUCCESS;
	}
	*//**
	 * 模糊查找所有标题列表
	 * @return
	 *
	public String getArticalTitlesByStatus2(){
		articalService=(ArticalService) SpringUtil.getBean("articalService");
		String url = "artical/getArticalTitlesByStatus2";
		
		System.out.println(artical.getTitle() +"           artical.getTitle()       ");
		pages = articalService.findByTitle((page - 1)*10, url , "三审已通过",artical.getTitle());
		return SUCCESS;
	}*/
	
	public String search() {
	    String url="json/articleSearch";
	    String keyword = super.getRequest().getParameter("keyword");
	    return SUCCESS;
	}
	/*--------不知道上面方法用到没--------*/
	
	
	public ArticalService getArticalService() {
		return articalService;
	}
	@Resource(name="articalService")
	public void setArticalService(ArticalService articalService) {
		this.articalService = articalService;
	}
	public Artical getArtical() {
		return artical;
	}
	public void setArtical(Artical artical) {
		this.artical = artical;
	}
	public String getArticalString() {
		return articalString;
	}
	public void setArticalString(String articalString) {
		this.articalString = articalString;
	}
	public int getValue() {
		return value;
	}
	public void setValue(int value) {
		this.value = value;
	}
	
}
